package com.wey.springboot.config;

import com.wey.springboot.interceptor.RedisUrlCountInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

@Configuration
public class WebConfig implements WebMvcConfigurer {
  private static final List<String> EXCLUDE_PATH =
      Arrays.asList("/", "css/**", "js/**", "img/**", "json/**", "fonts/**", "/*.html");
  @Autowired
  RedisUrlCountInterceptor redisUrlCountInterceptor;

  @Override
  public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(redisUrlCountInterceptor)
        .addPathPatterns("/**")
        .excludePathPatterns(EXCLUDE_PATH);
  }
}
